package com.ibeeking.found.open.api.feign.fallback;

import com.ibeeking.found.common.entity.open.OpenAuthDTO;
import com.ibeeking.found.common.entity.open.OpenAuthQuery;
import com.ibeeking.found.open.api.feign.OpenFeignClient;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class OpenFeignFallbackFactory implements FallbackFactory<OpenFeignClient> {
    @Override
    public OpenFeignClient create(Throwable throwable) {
        return new OpenFeignClient() {
            @Override
            public ResponseResult<List<OpenAuthDTO>> queryOpenAuthList(OpenAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询开放平台授权失败。" + throwable.getMessage(), Collections3.emptyList());
            }

            @Override
            public ResponseResult<OpenAuthDTO> queryOpenAuthOne(OpenAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询开放平台授权失败。" + throwable.getMessage(), null);
            }
        };
    }
}
